﻿using ShiXuLong.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShiXuLong.Service
{
    public class ShoesService
    {
        ShoesEntities db = new ShoesEntities();
        /// <summary>
        /// 根据指定条件获取商品列表所需的数据
        /// </summary>
        /// <returns></returns>
        public List<Shop> GetShoess(string shopName)
        {
            var lists = db.Shops.Where(p => true).ToList();
            if (!string.IsNullOrWhiteSpace(shopName))
            {
                lists = lists.Where(p => p.ShopName.Contains(shopName)).ToList();
            }
            return lists;
        }
        /// <summary>
        /// 商品详情
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public List<Shop> GetShoes(int ShopId=0)
        {
            var list = db.Shops.Where(p => p.RecommendId == 1 && p.Id == ShopId);
            return list.ToList();
        }
        /// <summary>
        /// 加购的方法
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int AddCart(int id)
        {
            var ShopList = db.Shops.Where(p => p.Id == id).SingleOrDefault();


            db.Carts.Add(new Cart
            {
                CarId = 1,
                UserId = 33,
                ProductId = ShopList.Id,
                ProductNum = 1,
                CreateTime = DateTime.Now,
                DataTime = DateTime.Now,
                StandardsId = 1
            });
            var res = db.SaveChanges();

            return res;

        }

        /// <summary>
        /// 获取轮播图表的所有数据
        /// </summary>
        /// <returns></returns>
        public List<LunBoModels> GetLunBo()
        {
            var lists = from c in db.LunBoTus.Where(p => true)
                        select new LunBoModels
                        {
                            Id = c.Id,
                            PictureId = c.PictureId,
                            ImageUrl = c.PictureUrl,
                            URL = c.URL
                        };


            var listss = lists.ToList();
            return listss;
        }
    }
}
